package com.kll.carolinehmibiz.net

import com.kll.carolinehmibiz.net.listener.DownloadListener
import okhttp3.Interceptor
import okhttp3.Response





/**
 * ====================================================
 * Created by Ziliang Cai on 2022/1/3 4:22 下午
 * <a href="mailto:752577456@qq.com">Contact me</a>
 * ====================================================
 */
class DownloadInterceptor: Interceptor {

    private var listener: DownloadListener? = null

    constructor(listener: DownloadListener) {
        this.listener = listener
    }

    override fun intercept(chain: Interceptor.Chain): Response {
        val originalResponse = chain.proceed(chain.request())

        return originalResponse.newBuilder()
            .body(DownloadResponseBody(originalResponse.body()!!, listener))
            .build()
    }
}